package demo523;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Delete {
    //1.把连接数据库的信放在一个类中,SqlConnection,在该类中定义一个方法getCon()
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Connection  connection=SqlConnection.getCon();
        Scanner  scanner=new Scanner(System.in);
        System.out.println("请输入用户的id");
        int id=scanner.nextInt();
        String sql="delete from users where id=?";
        PreparedStatement preparedStatement=connection.prepareStatement(sql);
        preparedStatement.setInt(1,id);
        int i=preparedStatement.executeUpdate();
        if(i>0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
